import instance from '@/utils/axios'

/* home首页接口 */
// 文章频道列表
function getChannelList() {
  return instance({
    url: '/v1_0/channels',
    method: "get"
  })

}
// 文章列表
function getArticleList({
  channel_id,
  timestamp
}) {
  return instance({
    url: '/v1_0/articles',
    method: "get",
    params: {
      with_top: 1,
      channel_id,
      timestamp,
    }
  })
}
//4.关注用户
const followUser = ({
  target
}) => {
  return instance({
    url: '/v1_0/user/followings',
    method: 'post',
    data: {
      target
    }
  })
}

//5.取消用户
const unFollowUser = ({
  target
}) => {
  return instance({
    //这个接口的id直接在路径后面拼接  格式： url/target
    url: '/v1_0/user/followings/' + target,
    method: 'delete',
  })
}
//导出接口
export {
  followUser,
  unFollowUser
}
/* 6.点赞与取消点赞 */

//点赞
const addPraise = id => {
  return instance({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: id
    }
  })
}

//取消点赞
const cancelPraise = id => {
  return instance({
    method: 'delete',
    //这个接口的id直接在路径后面拼接  格式： url/target
    url: '/v1_0/article/likings/' + id
  })
}

//导出接口
export {
  addPraise,
  cancelPraise
}
const getArticleInfo = ({
  id
}) => {
  return instance({
    //这个接口的id直接在路径后面拼接  格式： url/id
    url: '/v1_0/articles/' + id,
    method: 'get',
  })
}
//导出接口
export {
  getArticleInfo
}
// 导出接口
export {
  getChannelList
}
export {
  getArticleList
}
